home *** CD-ROM | disk | FTP | other *** search
/ ASME's Mechanical Engine…ing Toolkit 1997 December / ASME's Mechanical Engineering Toolkit 1997 December.iso / c_lang / pcca2com.lzh / ASM2COM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-09-02  |  2.9 KB  |  120 lines

  1. /*  ASM2COM.C - John Hensley - September 1, 1986
  2.  
  3.                 Converts DeSmet ASM88 files starting with INCLUDE "acom.inc" 
  4.                 to .COM files.
  5.                 All code and data must be in "cseg".
  6.                 Must use bind's -A option.
  7.                 This allows writing the very smallest programs in ASM88.
  8.  
  9.  
  10. EXAMPLE
  11.  
  12. -------------------------------------------------------------------------------
  13. ;NAME: TEST.A
  14. ;Example assembler source file with no C intialization, to be converted 
  15. ;to a .com file.
  16.  
  17. cseg
  18.  
  19. INCLUDE "acom.inc"
  20.  
  21.     mov  AH,09
  22.     mov  DX,&data
  23.     int  21h
  24.     int  20h
  25.  
  26. data    db  'This is a .com file.',13,'$'
  27.  
  28. end
  29. -------------------------------------------------------------------------------
  30.  
  31.                  ASM88 TEST
  32.  
  33.                  BIND  TEST -A
  34.  
  35.                  ASM2COM TEST
  36.  
  37. */
  38.  
  39.  
  40. #include "stdio.h"
  41.  
  42. #define  READ      00
  43.  
  44. main(argc, argv)
  45.  
  46. int argc;
  47. char *argv[]; 
  48.  
  49. {
  50.     int  infile;                       /* Input file handle          */
  51.     int  outfile;                      /* Output file handle         */
  52.     int  count;                        /* Keeps count of bytes read  */
  53.     char rw_buffer[4096];              /* I/O buffer for read & write */
  54.     char source[13];                   /* Source file ascii name     */
  55.     char destination[13];              /* Destination file ascii name */
  56.  
  57.     if ( argc <= 1 )
  58.          error( "Useage: ASM2COM file<.ext>\r\n"," " );
  59.  
  60.     file_names( argv[1], source, destination );
  61.  
  62.     if ( (infile = open( source, READ )) == ERR )
  63.          error( "Can't open %s.", source );
  64.  
  65.     if ( fseek(infile, 0x300L, 0) == ERR )
  66.          error( "ERROR setting input file pointer."," " );
  67.  
  68.     if ( (outfile = creat( destination )) == ERR )
  69.          error( "Can't create new file %s.", destination );
  70.  
  71.     while((count = read( infile, rw_buffer, 4096 )) > 0)
  72.          if ( write( outfile, rw_buffer, count  ) == 0 )
  73.          {
  74.               fclose( outfile );
  75.               unlink( destination );
  76.               error( "ERROR writing to output file.", " " );
  77.          }
  78.  
  79.     fclose(infile);
  80.     fclose(outfile);
  81.     unlink( source );
  82.  
  83. }
  84.  
  85.  
  86. error( string, data )               /* Error handler */
  87.  
  88. char     *string, *data;
  89.  
  90. {
  91.     printf(string, data);           /* Print the proper error message */
  92.     exit();                         /* Return to DOS */
  93. }
  94.  
  95.  
  96.  
  97.  
  98. file_names( argv, source, destination )     /* Creates a source and destination
  99.                                                ascii file names. */
  100. char     *argv, *source, *destination;
  101.  
  102. {
  103.     int  i = 0;
  104.     char letter;
  105.  
  106.     while( ( letter = toupper( *argv )) != '\0' && i < 8 && letter != '.' )
  107.     {
  108.          *(source++) = letter;
  109.          *(destination++) = letter;
  110.          i++;
  111.          argv++;
  112.     }
  113.     *source = '\0';
  114.     *destination = '\0';
  115.     strcat( source, ".EXE" );
  116.     strcat( destination, ".COM" );
  117.  
  118. }
  119.  
  120.